package org.herui.campus.service.properties;

import lombok.Data;
import org.herui.campus.properties.PropertyValueInfo;
import org.herui.campus.service.cache.config.CacheKeys;
import org.springframework.boot.context.properties.ConfigurationProperties;

import java.util.*;

/**
 * @author zzb
 * @version 1.0
 * @date 2024/2/1 14:51
 */
@ConfigurationProperties(prefix = "org.herui.campus.sys")
@Data
public class SysProperties extends BaseProperties{

    // 邮件注册码过期时间 秒
    private int mailCodeTimeOut = 3*60;

    //模板id
    private Integer modeId = 1;

    //发件人姓名
    private String nick = "发件人";

    private Map<String, List<PropertyValueInfo>> map = new HashMap<>();

    public void init(){
        List<PropertyValueInfo> propertyValueInfos = new LinkedList<>();
        propertyValueInfos.add(new PropertyValueInfo("weatherMaxTime", "每天最大天气查询次数", "1000",true));
        propertyValueInfos.add(new PropertyValueInfo("cityCount", "需要查询天气的城市数量", "2",false));
        propertyValueInfos.add(new PropertyValueInfo("interval", "间隔多少分钟查询一次天气","60", true));
        map.put(CacheKeys.SYS_ASK_WEATHER_KEY, propertyValueInfos);

        propertyValueInfos = new LinkedList<>();
        propertyValueInfos.add(new PropertyValueInfo("productKey", "产品key", "Nc2mzSAchh2",true));
        propertyValueInfos.add(new PropertyValueInfo("deviceName", "设备标识", "iot_sys_server",true));
        propertyValueInfos.add(new PropertyValueInfo("deviceSecret", "设备秘钥","PK7UQV27IZLR2NVcOrKtFJfeb19MHBCx", true));
        propertyValueInfos.add(new PropertyValueInfo("mqttAddr", "mqtt服务器地址","localhost", true));
        propertyValueInfos.add(new PropertyValueInfo("mqttPort", "mqtt服务器端口","1886", true));
        propertyValueInfos.add(new PropertyValueInfo("mqttGroup", "mqtt群组标识","iotSysGroup", false));
        map.put(CacheKeys.SYS_MQTT_PARAM_KEY, propertyValueInfos);

        propertyValueInfos = new LinkedList<>();
        propertyValueInfos.add(new PropertyValueInfo("mailCodeTimeOut", "邮件验证码超时时间",mailCodeTimeOut+"", false));
        propertyValueInfos.add(new PropertyValueInfo("paramnameSpace", "本机配置参数命名空间",paramnameSpace+"", false));
        map.put(CacheKeys.SYS_PARAM_KEY, propertyValueInfos);

        super.init();
    }

    public Map<String, List<PropertyValueInfo>> getMap() {
        return map;
    }

    @Override
    public String getTitle() {
        return "系统服务器";
    }

    public String getProductKey(){
        PropertyValueInfo propertyValueInfo = get(CacheKeys.SYS_MQTT_PARAM_KEY, "productKey");
        return propertyValueInfo.getValue();
    }
    public String getDeviceName(){
        PropertyValueInfo propertyValueInfo = get(CacheKeys.SYS_MQTT_PARAM_KEY, "deviceName");
        return propertyValueInfo.getValue();
    }
    public String getDeviceSecret(){
        PropertyValueInfo propertyValueInfo = get(CacheKeys.SYS_MQTT_PARAM_KEY, "deviceSecret");
        return propertyValueInfo.getValue();
    }
    public String getMqttAddr(){
        PropertyValueInfo propertyValueInfo = get(CacheKeys.SYS_MQTT_PARAM_KEY, "mqttAddr");
        return propertyValueInfo.getValue();
    }
    public int getMqttPort(){
        PropertyValueInfo propertyValueInfo = get(CacheKeys.SYS_MQTT_PARAM_KEY, "mqttPort");
        String value = propertyValueInfo.getValue();
        return Integer.valueOf(value);
    }
    public String getMqttGroup(){
        PropertyValueInfo propertyValueInfo = get(CacheKeys.SYS_MQTT_PARAM_KEY, "mqttGroup");
        return propertyValueInfo.getValue();
    }
}
